<?php

use Illuminate\Database\Seeder;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use App\Models\Search;

class SearchesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Excel::load(storage_path('assets/search.xlsx'), function(LaravelExcelReader $reader) {
            $data = $reader->toArray()[0];
            if (! Search::count()) {
                foreach ($data as $row) {
                    Search::create([
                        'key'   => current($row),
                        'tag'   => next($row),
                        'value' => next($row),
                    ]);
                }
            }
        });
    }
}
